#define _CRT_SECURE_NO_WARNINGS 1

struct ListNode* deleteDuplication(struct ListNode* pHead)
{
    if (pHead == NULL || pHead->next == NULL)
        return pHead;
    struct ListNode* cur = pHead;



    struct ListNode* newpHead = (struct ListNode*)malloc((sizeof(struct ListNode)));
    newpHead->next = NULL;
    struct ListNode* poi = newpHead;


    if (cur->val != cur->next->val && cur->next->next == NULL)
        return pHead;


    while (cur)
    {
        if (cur->val != cur->next->val)
        {
            poi->next = cur;
            cur = cur->next;
            poi = poi->next;
            if (cur->next == NULL)
            {
                poi->next = cur;
                poi = poi->next;
                break;
            }
        }
        else
        {
            struct ListNode* Next = cur->next;
            while (cur->val == Next->val && Next)
            {
                Next = Next->next;
            }
            cur = Next;
            if (cur == NULL)
                break;
            if (cur->next == NULL)
            {
                poi->next = cur;
                poi = poi->next;
                break;
            }
        }
    }
    poi->next = NULL;
    poi = newpHead;
    newpHead = newpHead->next;
    free(poi);
    return newpHead;

}